package com.fh.fruit.service.activity.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.fruit.entity.activity.ActivityRule;
import com.fh.fruit.service.activity.ActivityRuleManager;
import com.fh.util.PageData;

/**
 *活动规则
 * 
 * @author Administrator
 * @version 2017.11.30 15:39
 */
@Service("activityRuleService")
public class ActivityRuleService implements ActivityRuleManager {
	@Resource(name = "daoSupport")
	private DaoSupport dao;

	/**
	 * 获取活动规则
	* @author 葛欢欢
	* @version 2017.11.30 16:40 
	* @return
	* @throws Exception
	 */
	public List<ActivityRule> getActivityRule(Page page) throws Exception {
		// TODO Auto-generated method stub
		return (List<ActivityRule>) dao.findForList("ActivityRuleManager.getActivityRule",page);
	}

	/**
	  * 添加活动规则
	 * @author 葛欢欢
	 * @version 2017.11.30 16:40 
	 * @param ActivityRule
	 * @return
	 * @throws Exception PageData pd
	  */
	public int addActivityRule(PageData pd) throws Exception {
		// TODO Auto-generated method stub
		ActivityRule activityRule = new ActivityRule();
		activityRule.setActivityId(Integer.parseInt(pd.getString("activityId")));
		activityRule.setCondition(pd.getString("condition"));
		activityRule.setValue(pd.getString("value"));
		activityRule.setRemark(pd.getString("remark"));
		activityRule.setRuleTypeId(Integer.parseInt(pd.getString("ruleTypeId")));
		activityRule.setReserve1(pd.getString("reserve1"));
		activityRule.setReserve2(pd.getString("reserve2"));
		activityRule.setReserve3(pd.getString("reserve3"));
		activityRule.setReserve4(pd.getString("reserve4"));
		activityRule.setCreateId(pd.getString("createId"));
		activityRule.setCreateTime(pd.getString("createTime"));
		return (int) dao.save("ActivityRuleManager.addActivityRule", activityRule);
	}

	/**
	  * 修改活动规则
	 * @author 葛欢欢
	 * @version 2017.11.30 16:40 
	 * @param ActivityRule
	 * @return
	 * @throws Exception
	  */
	public int updateActivityRule(PageData pd) throws Exception {
		// TODO Auto-generated method stub
		ActivityRule activityRule = new ActivityRule();
		activityRule.setId(Integer.parseInt(pd.getString("id")));
		activityRule.setActivityId(Integer.parseInt(pd.getString("activityId")));
		activityRule.setCondition(pd.getString("condition"));
		activityRule.setValue(pd.getString("value"));
		activityRule.setRemark(pd.getString("remark"));
		activityRule.setRuleTypeId(Integer.parseInt(pd.getString("ruleTypeId")));
		activityRule.setReserve1(pd.getString("reserve1"));
		activityRule.setReserve2(pd.getString("reserve2"));
		activityRule.setReserve3(pd.getString("reserve3"));
		activityRule.setReserve4(pd.getString("reserve4"));
		activityRule.setUpdateId(pd.getString("updateId"));
		activityRule.setUpdateTime(pd.getString("updateTime"));
		activityRule.setCreateId(pd.getString("createId"));
		activityRule.setCreateTime(pd.getString("createTime"));
		return (int) dao.update("ActivityRuleManager.updateActivityRule", activityRule);
	}

	/**
	  * 删除活动规则
	 * @author 葛欢欢
	 * @version 2017.11.30 16:40 
	 * @param id
	 * @return
	 * @throws Exception
	  */
	public int deleteActivityRule(int id) throws Exception {
		// TODO Auto-generated method stub
		return (int) dao.delete("ActivityRuleManager.deleteActivityRule", id);
	}

	@Override
	public ActivityRule getActivityRuleById(int id) throws Exception {
		// TODO Auto-generated method stub
		return (ActivityRule) dao.findForObject("ActivityRuleManager.getActivityRuleById", id);
	}


}
